
#include <BImage>
#include <BImage>
#include <BFont>

#include <BTableItem>
#include "member_BTableItem.h"

using namespace BWE;

#define member					(*(member_BTableItem*)_ptr)
#define member_allocate()		_ptr = new member_BTableItem(this)
#define member_release()		delete (member_BTableItem*)_ptr

BTableItem::BTableItem()
{
	member_allocate();
}
BTableItem::BTableItem(const BString& text)
{
	member_allocate();
	setText(text);
}
BTableItem::~BTableItem()
{
	member_release();
}

void BTableItem::setAlign(Align align)
{
	if (member.align != align)
	{
		member.align = align;
		member.dirtyCell();
	}
}
Align BTableItem::align() const
{
	return member.align;
}

void BTableItem::setColor(const BColor& color)
{
	if (member.color != color)
	{
		member.color = color;
		member.dirtyCell();
	}
}
const BColor& BTableItem::color() const
{
	return member.color;
}

void BTableItem::setImage(BImage* image)
{
	if (member.image != image)
	{
		member.image = image;
		member.dirtyCell();
		member.dirty = true;
	}
}
BImage* BTableItem::image() const
{
	return member.image;
}

void BTableItem::setText(const BString& text)
{
	if (member.text != text)
	{
		member.text = text;
		member.dirtyCell();
	}
}
const BString& BTableItem::text() const
{
	return member.text;
}

void BTableItem::setWidget(BWidget* widget)
{
	if (member.widget != widget)
	{
		if (member.table)
			member.table->removeChild(member.widget);
		member.widget = widget;
		if (member.table)
			member.table->addChild(member.widget);
		member.dirty = true;
		member.dirtyCell();
	}
}
BWidget* BTableItem::widget()
{
	return member.widget;
}
const BWidget* BTableItem::widget() const
{
	return member.widget;
}

void BTableItem::setValue(const BValue& value)
{
	if (member.value != value)
	{
		member.value = value;
	}
}
const BValue& BTableItem::value() const
{
	return member.value;
}

int BTableItem::row() const
{
	if (member.table)
	{
		return member.row;
	}
	return -1;
}
int BTableItem::column() const
{
	if (member.table)
	{
		return member.column;
	}
	return -1;
}

const BRect& BTableItem::rect() const
{
	return member.rect;
}

BTableWidget* BTableItem::tableWidget()
{
	return member.table;
}
const BTableWidget* BTableItem::tableWidget() const
{
	return member.table;
}

void BTableItem::setEditable(bool editable)
{
	if (member.editable != editable)
	{
		member.editable = editable;
	}
}
bool BTableItem::editable() const
{
	return member.editable;
}

void BTableItem::setLineFeed(bool lineFeed)
{
	if (member.lineFeed != lineFeed)
	{
		member.lineFeed = lineFeed;
		member.dirtyCell();
	}
}
bool BTableItem::lineFeed() const
{
	return member.lineFeed;
}

bool BTableItem::isSelected() const
{
	if (member.table)
		return table_member(member.table)->selectedItems.contain(this);
	return false;
}

